// index.js
require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const userRoutes = require("./routes/userRoutes");
const articleRoutes = require("./routes/articleRoutes");
const wordRoutes = require("./routes/wordRoutes");
const wordsetRoutes = require("./routes/wordssetRoutes");
const testRoutes = require("./routes/testRoutes");
const dailySentence = require("./routes/dailySentence");
const extendArticleType = require("./routes/extendArticleType");
const extendArticle = require("./routes/extendArticle");
const banner = require("./routes/banner");
const etymologyType = require("./routes/etymologyType");
const etymology = require("./routes/etymology");
const enWords = require("./routes/enWords");
const product = require("./routes/product");
const type = require("./routes/type");
const shop = require("./routes/shop");
const order = require("./routes/order");
const cors = require("cors");
const path = require("path");
const app = express();
app.use(cors());
app.use(bodyParser.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
// 设置端口
const PORT = process.env.PORT || 3000;
app.use("/", express.static(path.join(__dirname, "./public/")));

app.use(express.json());
const apiRoutes = express.Router();
apiRoutes.use("/user", userRoutes);
apiRoutes.use("/article", articleRoutes);
apiRoutes.use("/word", wordRoutes);
apiRoutes.use("/set", wordsetRoutes);
apiRoutes.use("/test", testRoutes);
apiRoutes.use("/dailySentence", dailySentence);
apiRoutes.use("/extendArticleType", extendArticleType);
apiRoutes.use("/extendArticle", extendArticle);
apiRoutes.use("/banner", banner);
apiRoutes.use("/etymologyType", etymologyType);
apiRoutes.use("/etymology", etymology);
apiRoutes.use("/enWords", enWords);
apiRoutes.use("/order", order);
apiRoutes.use("", product);
apiRoutes.use("", shop);
apiRoutes.use("", type);
// // 使用用户路由
app.use("/api", apiRoutes);

app.listen(PORT, () => {
	console.log(`Server running on port ${PORT}`);
});
